//
//  ZBNavifationController.swift
//  ZBWb
//
//  Created by 天隐翎 on 16/4/10.
//  Copyright © 2016年 csdn. All rights reserved.
//

import UIKit

class ZBNavifationController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = self

        // Do any additional setup after loading the view.
    }

    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        
        if childViewControllers.count>0 {
            
        var backtitle = "返回"
        
        if childViewControllers.count == 1{
            
            backtitle = childViewControllers.first?.title ?? ""
        }
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: backtitle, target: self, action: "back")
            
            viewController.hidesBottomBarWhenPushed = true
            
            viewController.view.backgroundColor = UIColor.whiteColor()
        }
        super.pushViewController(viewController, animated: animated)
        
    }
    
    @objc func back(){
        self.popViewControllerAnimated(true)
    }
//    MARK 手势的代理方法
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return childViewControllers.count != 1
    }

}
